package config

import (
	"common/helper"
	"database/sql"
)

/*
打码配置
*/

type CfgFlowItem struct {
	Type    int     `json:"ty" db:"ty" cbor:"ty"`
	FlowMul float64 `json:"flow_multiple" db:"flow_multiple" cbor:"flow_multiple"`
}
type CsFlowCfg struct {
}

var cfgFlowList []CfgFlowItem

func FlowCfgSetRow(rows *sql.Rows) {
	var tVal CfgFlowItem
	var err error
	err = rows.Scan(&tVal.Type, &tVal.FlowMul)
	if err != nil {
		helper.InfoLog("FlowCfgSetRow,scan err")
		return
	}

	cfgFlowList = append(cfgFlowList, tVal)
}

func FlowCfgRemove() {
	cfgFlowList = []CfgFlowItem{}
}

func GetFlowMul(channelId int, ty int) float64 {

	fChannelWaged := GetChannelWagedMul(channelId, ty)
	if fChannelWaged >= 0.0 {
		return fChannelWaged
	}

	nLen := len(cfgFlowList)
	for index := 0; index < nLen; index++ {
		if cfgFlowList[index].Type == ty {
			return cfgFlowList[index].FlowMul
		}
	}

	return 0.0
}
